package com.koron.device.bean;

import cn.hutool.core.util.StrUtil;
import com.koron.bean.base.BaseBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author jkw
 * @description: TODO
 * @date 2021/7/7 17:14
 */
@Data
@AllArgsConstructor
@ApiModel(value = "设备台账", description = "设备台账")
public class    Equipment extends BaseBean implements Serializable {

    /**
     * 设备系统编码
     */
    @ApiModelProperty(value = "设备系统编码")
    private String code;

    @ApiModelProperty(value = "amdCode")
    private String amdCode;

    @ApiModelProperty(value = "waterType")
    private String waterType;

    /**
     * 设备名称
     */
    @ApiModelProperty(value = "设备名称")
    private String name;

    /**
     * 父级编码
     */
    @ApiModelProperty(value = "父级设备id")
    private String parentId;

    /**
     * 父级名称
     */
    @ApiModelProperty(value = "父级设备名称")
    private String parentName;

    /**
     * 层级
     */
    @ApiModelProperty(value = "层级")
    private Integer level;

    /**
     * 层级编码
     */
    @ApiModelProperty(value = "层级编码")
    private Integer levelCode;

    /**
     * 层级路径
     */
    @ApiModelProperty(value = "层级路径")
    private String levelPath;

    @ApiModelProperty(value = "全路径设备台账id")
    private String fullPathCode;

    @ApiModelProperty(value = "全路径设备台账名称")
    private String fullPathName;

    /**
     * kks编码
     */
    @ApiModelProperty(value = "kks编码")
    private String encode;

    @ApiModelProperty(value = "组织id")
    private String deptId;

    /**
     * 设备分类编码
     */
    @ApiModelProperty(value = "设备分类编码")
    private String typeId;

    /**
     * 设备分类名称
     */
    @ApiModelProperty(value = "设备分类名称")
    private String typeName;

    /**
     * 业务层级
     */
    @ApiModelProperty(value = "业务层级，水司、部门、......")
    private String floor;

    /**
     * 是否虚拟节点
     */
    @ApiModelProperty(value = "是否虚拟节点（1：是，0：否）")
    private String isVirtual;

    @ApiModelProperty("预设参数json格式")
    private String inAdvanceParam;

    @ApiModelProperty("专业")
    private String major;

    @ApiModelProperty("位置编码")
    private String locCode;

    @ApiModelProperty("工艺")
    private String subProcessCode;

    @ApiModelProperty("amd专业")
    private String assetGroupCode;

    @ApiModelProperty("是否泵站水厂主体 1是 0ornull不是")
    private Integer ismain = 0;

    @ApiModelProperty("展示类型 locCode、subProcessCode、assetGroupCode,分别是位置、工艺、专业")
    private String soViewType;

    /**
     * 状态
     */
    @ApiModelProperty(value = "状态（1：启用，0：停用）")
    private String status;

    /**
     * 排序字段
     */
    @ApiModelProperty(value = "排序字段")
    private Integer sort;

    @ApiModelProperty(value = "基础参数")
    private List<EquipmentParams> basicParams;

    @ApiModelProperty(value = "技术参数")
    private List<EquipmentParams> techParams;

    @ApiModelProperty("技术参数和基础参数集合")
    private List<EquipmentParams> params;

    @ApiModelProperty(value = "子节点")
    private List<Equipment> children;

    @ApiModelProperty(value = "组织名称")
    private String deptName;

    @ApiModelProperty(value = "是否有子集")
    private Boolean hasChildren;

    @ApiModelProperty(value = "子集个数")
    private Integer childrenNum;

    @ApiModelProperty("是否有设备管理单位")
    private Boolean hasManagerUnit;

    @ApiModelProperty("根据设备管理单位过滤后")
    private Boolean filterManagerUnit;

    @ApiModelProperty("根据标准类型和设备分类过滤")
    private Boolean filterStandard;

    @ApiModelProperty("数据来源")
    private String dataSources;

    @ApiModelProperty("kks分类编码")
    private String kksCode;

    public Equipment() {}

    public List<EquipmentParams> getParams() {
        if(CollectionUtils.isNotEmpty(params)) {
            return this.params;
        }
        if(Objects.isNull(basicParams)) {
            basicParams = new ArrayList<>();
        }
        if(Objects.isNull(techParams)) {
            techParams = new ArrayList<>();
        }
        return ListUtils.union(basicParams, techParams);
    }

    public Boolean getHasChildren() {
        return childrenNum != null && this.childrenNum > 0;
    }

    /**
     * 设备简称（只带后缀）
     * 如父类：#1机组   子类：#1机组主水泵
     * 则返回 主水泵
     * @return 去掉父类前缀
     */
    public String getShortName() {
        return StrUtil.strip(name, parentName, "");
    }
}
